import * as Cesium from 'cesium'
import gsap from 'gsap'
export class LightCone {
    constructor(viewer) {
        this.longitude = 113.3191
        this.latitude = 23.109
        this.params = {
            height: 700,
            degress: 0
        }
        this.position = Cesium.Cartesian3.fromDegrees(this.longitude, this.latitude, this.params.height)
        this.modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
            this.position, //位置
            new Cesium.HeadingPitchRoll(this.params.degress, 0, 0) // 旋转
        )
        this.viewer = viewer
        this.init()
    }
    async init() {
        let pri = await Cesium.Model.fromGltfAsync({
            url: './model/pri.glb',
            show: true,
            scale: 30,
            minimumPixelSize: 12,
            maximumScale: 20000,
            allowPicking: false,
            debugShowBoundingVolume: false,
            debugWireframe: false,
            color: Cesium.Color.YELLOW.withAlpha(0.5),
            colorBlendMode: Cesium.ColorBlendMode.MIX,
            modelMatrix: this.modelMatrix
        })
        this.model = this.viewer.scene.primitives.add(
            pri
        )
        // const modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
        //     this.position,
        //     new Cesium.HeadingPitchRoll(this.params.degress, 0, 0) // 旋转
        // );
        // var xAxisDirection = new Cesium.Cartesian3(100.0, 100.0, 0.0);
        // const modelMatrix1 = Cesium.Transforms.headingPitchRollToFixedFrame(
        //     Cesium.Cartesian3.add(this.position, xAxisDirection, new Cesium.Cartesian3()),
        //     new Cesium.HeadingPitchRoll(this.params.degress, 0, 0) // 旋转
        // );
        // // X轴：红色，Y轴：绿色，Z轴：蓝色
        // this.viewer.scene.primitives.add(
        //     new Cesium.DebugModelMatrixPrimitive({
        //         modelMatrix: modelMatrix,
        //         length: 300.0,
        //         width: 10.0,
        //     })
        // );
        // this.viewer.scene.primitives.add(
        //     new Cesium.DebugModelMatrixPrimitive({
        //         modelMatrix: modelMatrix1,
        //         length: 300.0,
        //         width: 10.0,
        //     })
        // );
        this.animati()
    }
    animati() {
        gsap.to(this.params, {
            height: 800,
            degress: Math.PI,
            yoyo: true,
            repeat: -1,
            duration: 1,
            ease: 'power1.inOut',
            onUpdate: () => {
                this.model.modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
                    Cesium.Cartesian3.fromDegrees(this.longitude, this.latitude,this.params.height), //位置
                    new Cesium.HeadingPitchRoll(this.params.degress,0,0) // 旋转
                )
            }
        })
    }
}